package acm.pta7;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class 分而治之 {
    public static void main(String[] args) {
        Reader sc=new Reader();
        int n = sc.nextInt();
        int m = sc.nextInt();
        Graph graph = new Graph(n);
        for (int i = 0; i < m; i++) {
            graph.insert(sc.nextInt(),sc.nextInt());
        }
        int k=sc.nextInt();
        while (k-- > 0) {
            int count = sc.nextInt();
            Set<Integer> set = new HashSet<>();
            while (count-->0){
                set.add(sc.nextInt());
            }
            if (graph.fun(set)) {
                System.out.println("YES");
            }else {
                System.out.println("NO");
            }
        }
    }
    static class Graph{
        List<Integer>[] map;
//        boolean[][] map;
        public Graph(int size) {
//            this.map=new boolean[size+1][size+1];
            this.map=new List[size+1];
            for (int i = 0; i < map.length; i++) {
                map[i]=new LinkedList<>();
            }
        }
        public void insert(int from,int to){
            map[from].add(to);
            map[to].add(from);
//            map[from][to]=true;
        }
        public boolean fun(Set<Integer> set){
            for (int i = 1; i < map.length; i++) {
                if (!set.contains(i)){
                    for (Integer t : map[i]) {
                        if (!set.contains(t)){  //可以走向一个未被轰炸的城市
                            return false;
                        }
                    }
//                    for (int j = 1; j < map[i].length; j++) {
//                        if (map[i][j]&&!set.contains(j)){
//                            return false;
//                        }
//                    }
                }
            }
            return true;
        }
    }
    static class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}
